/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminFilmSchedule.java
 *
 * Created on May 1, 2012, 11:06:57 AM
 */
package GUI.Admin;

import dao.LichChieuPhimDAO;
import dao.PhimDAO;
import dao.PhongChieuDAO;
import dao.SuatChieuDAO;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.ActionMap;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.Task;
import pojo.Lichchieuphim;
import pojo.Phim;
import pojo.Phongchieu;
import pojo.Suatchieu;
import utils.BusyIndicator;
import utils.BusyIndicatorInputBlocker;
import utils.ClassUtils;

/**
 *
 * @author Hnmtuan
 */
public class AdminFilmSchedule extends javax.swing.JPanel {

    // <editor-fold defaultstate="collapsed" desc="Define all variables using this application">
    private SingleFrameApplication localApplication;
    private DefaultTableModel _scheduleModel;
    private DefaultComboBoxModel _cbFilmModel, _cbRoomModel, _cbShowTimeModel;
    private BusyIndicator localBusy;
    private ActionMap _rsActionMap;
    private List<Phim> _films;
    private List<Phongchieu> _rooms;
    private List<Suatchieu> _showTimes;
    private List<Lichchieuphim> _schedules;
    private boolean saveNeeded, cancelSelected, newRow;
    private static int DEFAULT_INDEX_COMBO = 0;
    // </editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Define messages and error messages" >
    private final String MSG_LOADING = "Reloading list schedules  .... !";
    private final String MSG_SAVE_SUCCESS = "Insert schedule successfully";
    private final String MSG_SAVE_BEGINNING = "Begin saving .... !";
    private final String MSG_SAVE_DATABASE = "Saving database  .... !";
    private final String MSG_DELETE_SUCCESS = "Delete schedule successfully";
    private final String MSG_DELETE_BEGINNING = "Begin deleteing .... !";
    private final String MSG_DELETE_DATABASE = "Deleteing database  .... !";
    private final String MSG_DELETE_CONFIRM = "Do you want to delete %s ?";
    private final String MSG_DELETE_TITLE = "Delete Film Schedule";
    private final String MSG_UPDATE_SUCCESS = "Update schedules successfully";
    private final String MSG_UPDATE_BEGINNING = "Begin updating .... !";
    private final String MSG_UPDATE_DATABASE = "Updating database  .... !";
    private final String ERR_LIST_EMPTY = "Schedule list is empty";
    private final String ERR_FILMS_LIST_EMPTY = "Film list is empty";
    private final String ERR_ROOMS_LIST_EMPTY = "Room list is empty";
    private final String ERR_SHOW_TIMES_LIST_EMPTY = "Show times list is empty";
    private final String ERR_SAVE_TASK = "Save task not done !";
    private final String ERR_SELECT_OUTOFBOUND = "You select out of bound !";
    private final String ERR_SELECTED_TYPE_EMPTY = "Selected type is empty";
    private final String ERR_INVALID_PARAMS = "Invalid parameters !";
    private final String ERR_DELETE_INVALID_PARAMS = "Delete invalid parameters !";
    private final String ERR_DELETE_TASK = "Delete task not done !";
    private final String ERR_UPDATE_INVALID_PARAMS = "Update invalid parameters !";
    private final String ERR_UPDATE_TASK = "Update task not done !";
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Constructor" >

    public AdminFilmSchedule(SingleFrameApplication appContext, BusyIndicator busy) throws Exception {
        localApplication = appContext;
        localBusy = busy;
        initComponents();
        initActions();
        loadRooms();
        loadFilms();
        loadShowTimes();
        loadSchedules();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Init Actions" >

    private void initActions() throws Exception {
        _rsActionMap = Application.getInstance(main.MainFormApp.class).getContext().getActionMap(getClass(), this);
        jbtnSearch.setAction(_rsActionMap.get("searchFilms"));
        jbtnAdd.setAction(_rsActionMap.get("addRow"));
        jbtnUpdate.setAction(_rsActionMap.get("updateRow"));
        jbtnDelete.setAction(_rsActionMap.get("deleteRow"));
        jbtnCancel.setAction(_rsActionMap.get("cancelRow"));
        setNewRow(true);
        jtbFilmSchedules.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            // -->>> not revoiked event throws exception

            public void valueChanged(ListSelectionEvent e) {
                if (isRecordSelected()) {
                    loadFields();
                }
                firePropertyChange("recordSelected", !isRecordSelected(), isRecordSelected());
                setSaveNeeded(true);
                setCancelSelected(true);
                setNewRow(false);
            }
        });
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Actions">
    @Action
    public void searchFilms() {
//        Task task = new SearchTask();
//        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
//        return task;
    }

    @Action(enabledProperty = "newRow")
    public Task addRow() {
        Task task = new SaveTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "saveNeeded")
    public Task updateRow() {
        Task task = new UpdateTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "recordSelected")
    public Task deleteRow() {
        Task task = new DeleteTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "cancelSelected")
    public void cancelRow() {
        defaultButtonState();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Property or State">

    public boolean isCancelSelected() {
        return cancelSelected;
    }

    public boolean isSaveNeeded() {
        return saveNeeded;
    }

    public boolean isNewRow() {
        return newRow;
    }

    public boolean isRecordSelected() {
        return jtbFilmSchedules.getSelectedRow() != -1;
    }

    public void setSaveNeeded(boolean saveNeeded) {
        if (saveNeeded != this.saveNeeded) {
            this.saveNeeded = saveNeeded;
            firePropertyChange("saveNeeded", !this.saveNeeded, this.saveNeeded);
        }
    }

    public void setCancelSelected(boolean cancelSelected) {
        if (cancelSelected != this.cancelSelected) {
            this.cancelSelected = cancelSelected;
            firePropertyChange("cancelSelected", !this.cancelSelected, this.cancelSelected);
        }
    }

    public void setNewRow(boolean newRow) {
        if (newRow != this.newRow) {
            this.newRow = newRow;
            firePropertyChange("newRow", !this.newRow, this.newRow);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement Actions to GUI" >

    protected final void setSelectedShowTime(String startTime) throws Exception {
        if (startTime.isEmpty()) {
            throw new Exception(ERR_INVALID_PARAMS);
        }
        if (_showTimes == null || _showTimes.size() < 1) {
            throw new Exception(ERR_SHOW_TIMES_LIST_EMPTY);
        }
        boolean foundFlag = false;
        int searchIndex = -1;
        for (Suatchieu item : _showTimes) {
            searchIndex++;
            if (item.getGioBatDau().equalsIgnoreCase(startTime)) {
                foundFlag = true;
                break;
            }
        }
        searchIndex = (!foundFlag) ? DEFAULT_INDEX_COMBO : searchIndex;
        jcbShowTimes.setSelectedIndex(searchIndex);
    }

    protected final void setSelectedFilm(String nameFilm) throws Exception {
        if (nameFilm.isEmpty()) {
            throw new Exception(ERR_INVALID_PARAMS);
        }
        if (_films == null || _films.size() < 1) {
            throw new Exception(ERR_FILMS_LIST_EMPTY);
        }
        boolean foundFlag = false;
        int searchIndex = -1;
        for (Phim item : _films) {
            searchIndex++;
            if (item.getTenPhim().equalsIgnoreCase(nameFilm)) {
                foundFlag = true;
                break;
            }
        }
        searchIndex = (!foundFlag) ? DEFAULT_INDEX_COMBO : searchIndex;
        jcbFilm.setSelectedIndex(searchIndex);
    }

    protected final void setSelectedRoom(String nameRoom) throws Exception {
        if (nameRoom.isEmpty()) {
            throw new Exception(ERR_INVALID_PARAMS);
        }
        if (_rooms == null || _rooms.size() < 1) {
            throw new Exception(ERR_ROOMS_LIST_EMPTY);
        }
        boolean foundFlag = false;
        int searchIndex = -1;
        int maxSize = _rooms.size();
        for (Phongchieu item : _rooms) {
            searchIndex++;
            if (item.getTenPhong().equalsIgnoreCase(nameRoom)) {
                foundFlag = true;
                break;
            }
        }
        searchIndex = (!foundFlag) ? DEFAULT_INDEX_COMBO : searchIndex;
        jcbRoom.setSelectedIndex(searchIndex);
    }

    protected final void loadFields() {
        try {
            if (_schedules == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int maxSize = _schedules.size();
            int selectedRow = jtbFilmSchedules.getSelectedRow(); //row which you select into JTable
            if (selectedRow > maxSize) {
                throw new Exception(ERR_SELECT_OUTOFBOUND);
            }
            Lichchieuphim selectedSchedule = _schedules.get(selectedRow);
            if (selectedSchedule == null) {
                throw new Exception(ERR_SELECTED_TYPE_EMPTY);
            }
            jdStartingDate.setDate(selectedSchedule.getNgayChieu());
            setSelectedRoom(selectedSchedule.getPhongchieu().getTenPhong());
            setSelectedFilm(selectedSchedule.getPhim().getTenPhim());
            setSelectedShowTime(selectedSchedule.getSuatchieu().getGioBatDau());
        } catch (Exception e) {
            //System.out.println(String.format("Error: %s", e.getMessage()));
            e.printStackTrace(); //-->>> show remove this code
        }
    }

    protected final void clearAllTextField() {
        jdStartingDate.setDate(null);
    }

    protected final void defaultButtonState() {
        clearAllTextField();
        jtbFilmSchedules.clearSelection();
        defaultAllComboBox();
        firePropertyChange("recordSelected", isRecordSelected(), !isRecordSelected());
        setSaveNeeded(false);
        setCancelSelected(false);
        setNewRow(true);
    }

    protected final void defaultAllComboBox() {
        jcbRoom.setSelectedIndex(DEFAULT_INDEX_COMBO);
        jcbFilm.setSelectedIndex(DEFAULT_INDEX_COMBO);
        jcbShowTimes.setSelectedIndex(DEFAULT_INDEX_COMBO);
    }

    protected final Suatchieu getSelectedShowTime() throws Exception {
        Suatchieu cachedShowTime = null;
        if (_showTimes == null || _showTimes.size() < 1) {
            throw new Exception(ERR_FILMS_LIST_EMPTY);
        }
        int selectedIndex = jcbShowTimes.getSelectedIndex();
        cachedShowTime = _showTimes.get(selectedIndex);
        return cachedShowTime;
    }

    protected final Phim getSelectedFilm() throws Exception {
        Phim cachedFilm = null;
        if (_films == null || _films.size() < 1) {
            throw new Exception(ERR_FILMS_LIST_EMPTY);
        }
        int selectedIndex = jcbFilm.getSelectedIndex();
        cachedFilm = _films.get(selectedIndex);
        return cachedFilm;
    }

    protected final Phongchieu getSelectedRoom() throws Exception {
        Phongchieu cachedRoom = null;
        if (_rooms == null || _rooms.size() < 1) {
            throw new Exception(ERR_ROOMS_LIST_EMPTY);
        }
        int selectedIndex = jcbRoom.getSelectedIndex();
        cachedRoom = _rooms.get(selectedIndex);
        return cachedRoom;
    }

    protected final void loadSchedules() throws Exception {
        _scheduleModel = (DefaultTableModel) jtbFilmSchedules.getModel();
        _scheduleModel.getDataVector().clear();
        try {
            _schedules = LichChieuPhimDAO.getLichChieuPhims();
            if (_schedules == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int count = 0;
            for (Lichchieuphim item : _schedules) {
                Vector v = new Vector();
                count = count + 1;
                v.addElement(item.getNgayChieu());
                v.addElement(item.getPhim().getTenPhim());
                v.addElement(item.getPhongchieu().getTenPhong());
                v.addElement(String.format("%s - %s", item.getSuatchieu().getGioBatDau(), item.getSuatchieu().getGioKetThuc()));
                _scheduleModel.addRow(v);
            }
            jtbFilmSchedules.setModel(_scheduleModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        } finally {
            LichChieuPhimDAO.closeCurrentSession();
        }
    }

    protected final void loadShowTimes() throws Exception {
        _cbShowTimeModel = (DefaultComboBoxModel) jcbShowTimes.getModel();
        _cbShowTimeModel.removeAllElements();
        try {
            _showTimes = SuatChieuDAO.getSuatChieus();
            if (_showTimes == null) {
                throw new Exception(ERR_SHOW_TIMES_LIST_EMPTY);
            }
            int count = 0;
            for (Suatchieu showTime : _showTimes) {
                String stime = String.format("%s - %s", showTime.getGioBatDau(), showTime.getGioKetThuc());
                _cbShowTimeModel.addElement(stime);
            }
            jcbShowTimes.setModel(_cbShowTimeModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
    }

    protected final void loadRooms() throws Exception {
        _cbRoomModel = (DefaultComboBoxModel) jcbRoom.getModel();
        _cbRoomModel.removeAllElements();
        try {
            _rooms = PhongChieuDAO.getPhongChieus();
            if (_rooms == null) {
                throw new Exception(ERR_ROOMS_LIST_EMPTY);
            }
            int count = 0;
            for (Phongchieu room : _rooms) {
                _cbRoomModel.addElement(room.getTenPhong());
            }
            jcbRoom.setModel(_cbRoomModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        } finally {
            PhongChieuDAO.closeCurrentSession();
        }
    }

    protected final void loadFilms() throws Exception {
        _cbFilmModel = (DefaultComboBoxModel) jcbFilm.getModel();
        _cbFilmModel.removeAllElements();
        try {
            _films = PhimDAO.getPhims();
            if (_films == null) {
                throw new Exception(ERR_FILMS_LIST_EMPTY);
            }
            int count = 0;
            for (Phim film : _films) {
                _cbFilmModel.addElement(film.getTenPhim());
            }
            jcbFilm.setModel(_cbFilmModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        } finally {
            PhimDAO.closeCurrentSession();
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Delete Task" >

    private class DeleteTask extends Task<Void, Void> {

        public DeleteTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_DELETE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get object is selected to delete
            int selectedIndex = jtbFilmSchedules.getSelectedRow();
            if (_schedules == null || selectedIndex == -1) {
                throw new Exception(ERR_DELETE_INVALID_PARAMS);
            }
            Lichchieuphim cachedSchedule = _schedules.get(selectedIndex);
            String msg = String.format(MSG_DELETE_CONFIRM, cachedSchedule.getIdLichChieuPhim().toString());
            int returnOptionDialog = JOptionPane.showConfirmDialog(localApplication.getMainFrame(), msg, MSG_DELETE_TITLE, JOptionPane.OK_CANCEL_OPTION);
            if (returnOptionDialog == JOptionPane.CANCEL_OPTION) {
                return null;
            }
            setMessage(MSG_DELETE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Delete database
            LichChieuPhimDAO.deleteLichChieuPhims(cachedSchedule);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadSchedules();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_DELETE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            defaultButtonState();
            setMessage(MSG_DELETE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Update Task" >

    private class UpdateTask extends Task<Void, Void> {

        public UpdateTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_UPDATE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get information and prepare object
            int selectedIndex = jtbFilmSchedules.getSelectedRow();
            if (_schedules == null || selectedIndex == -1) {
                throw new Exception(ERR_UPDATE_INVALID_PARAMS);
            }
            Lichchieuphim cachedSchedule = _schedules.get(selectedIndex);
            Date startingDate = jdStartingDate.getDate();
            Phongchieu room = getSelectedRoom();
            Phim film = getSelectedFilm();
            Suatchieu showTime = getSelectedShowTime();

            cachedSchedule.setNgayChieu(startingDate);
            cachedSchedule.setPhongchieu(room);
            cachedSchedule.setPhim(film);
            cachedSchedule.setSuatchieu(showTime);

            setMessage(MSG_UPDATE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Update to database
            LichChieuPhimDAO.updateLichChieuPhims(cachedSchedule);
            // Loading gui
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadSchedules();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_UPDATE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {            
            defaultButtonState();
            setMessage(MSG_UPDATE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Save Task" >

    private class SaveTask extends Task<Void, Void> {

        public SaveTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SAVE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get all information from fields
            Date startingDate = jdStartingDate.getDate();
            Phongchieu room = getSelectedRoom();
            Phim film = getSelectedFilm();
            Suatchieu showTime = getSelectedShowTime();
            // Prepare object
            Lichchieuphim cachedSchedule = new Lichchieuphim(showTime, room, film,
                    startingDate, ClassUtils.StateFields.DEFAULT_STATUS, null);
            setMessage(MSG_SAVE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Save into database
            LichChieuPhimDAO.insertLichChieuPhims(cachedSchedule);
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadSchedules();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SAVE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SAVE_SUCCESS);
            setProgress(4, 0, 4);
            defaultButtonState();
        }
    }
    // </editor-fold>

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jdStartingDate = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jcbRoom = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jcbFilm = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jcbShowTimes = new javax.swing.JComboBox();
        jbtnSearch = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbFilmSchedules = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jbtnAdd = new javax.swing.JButton();
        jbtnUpdate = new javax.swing.JButton();
        jbtnDelete = new javax.swing.JButton();
        jbtnCancel = new javax.swing.JButton();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminFilmSchedule"); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpSearchForm.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jdStartingDate.setName("jdStartingDate"); // NOI18N

        jLabel1.setText(bundle.getString("jlbStartingDate.title")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(bundle.getString("jlbRoom.title")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jcbRoom.setName("jcbRoom"); // NOI18N

        jLabel3.setText(bundle.getString("jlbFilm.title")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jcbFilm.setName("jcbFilm"); // NOI18N

        jLabel4.setText(bundle.getString("jlbShowTimes.title")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jcbShowTimes.setName("jcbShowTimes"); // NOI18N

        jbtnSearch.setText(bundle.getString("jbtnSearch.title")); // NOI18N
        jbtnSearch.setName("jbtnSearch"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(47, 47, 47)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jcbShowTimes, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbFilm, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbRoom, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jdStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)
                .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(68, 68, 68))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jdStartingDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jcbRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jcbFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jcbShowTimes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpListSchedule.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtbFilmSchedules.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Date", "Film", "Room", "Show Times"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbFilmSchedules.setName("jtbFilmSchedules"); // NOI18N
        jtbFilmSchedules.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbFilmSchedules);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpAction.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jbtnAdd.setText(bundle.getString("jbtnAddSchedule.title")); // NOI18N
        jbtnAdd.setName("jbtnAdd"); // NOI18N

        jbtnUpdate.setText(bundle.getString("jbtnUpdateSchedule.title")); // NOI18N
        jbtnUpdate.setName("jbtnUpdate"); // NOI18N

        jbtnDelete.setText(bundle.getString("jbtnDeleteRoom.title")); // NOI18N
        jbtnDelete.setName("jbtnDelete"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(AdminFilmSchedule.class);
        jbtnCancel.setText(resourceMap.getString("jbtnCancel.title")); // NOI18N
        jbtnCancel.setName("jbtnCancel"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(jbtnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addComponent(jbtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addComponent(jbtnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jbtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnCancel)
                    .addComponent(jbtnAdd)
                    .addComponent(jbtnUpdate)
                    .addComponent(jbtnDelete))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnAdd;
    private javax.swing.JButton jbtnCancel;
    private javax.swing.JButton jbtnDelete;
    private javax.swing.JButton jbtnSearch;
    private javax.swing.JButton jbtnUpdate;
    private javax.swing.JComboBox jcbFilm;
    private javax.swing.JComboBox jcbRoom;
    private javax.swing.JComboBox jcbShowTimes;
    private com.toedter.calendar.JDateChooser jdStartingDate;
    private javax.swing.JTable jtbFilmSchedules;
    // End of variables declaration//GEN-END:variables
}
